var shortid = require('shortid')
// 生成min-max范围的随机数
var randomNum = (min, max) => {
  let num = Math.floor(Math.random() * (max - min)) + min
  return num
}
// 当前时间
function getNow (s) {
  return s < 10 ? '0' + s : s;
}

var nowYMD = () => {
  var myDate = new Date();
  //获取当前年
  var year = myDate.getFullYear();
  //获取当前月
  var month = myDate.getMonth() + 1;
  //获取当前日
  var date = myDate.getDate();
  return year + '.' + month + '.' + date;
}
var nowHM = () => {
  var myDate = new Date();
  var h = myDate.getHours();       //获取当前小时数(0-23)
  var m = myDate.getMinutes();     //获取当前分钟数(0-59)
  var s = myDate.getSeconds();

  return getNow(h) + ':' + getNow(m) + ':' + getNow(s);
}
var setId = (param) => {
  return year + month + date + shortid.generate() + param + getNow(h) + getNow(m);
}
module.exports = {
  randomNum,
  nowYMD,
  nowHM,
  setId
};